package com.farm.dto;

import java.math.BigDecimal;
import java.util.List;

import com.farm.entity.CartItem;
import com.farm.entity.User;

public class CartGroupDTO {
    private User farmer;
    private List<CartItem> items;
    private BigDecimal subtotal;

    public CartGroupDTO(User farmer, List<CartItem> items) {
        this.farmer = farmer;
        this.items = items;
        this.subtotal = calculateSubtotal();
    }

    private BigDecimal calculateSubtotal() {
        return items.stream()
                .map(item -> item.getProduct().getPrice().multiply(BigDecimal.valueOf(item.getQuantity())))
                .reduce(BigDecimal.ZERO, BigDecimal::add);
    }

    public User getFarmer() {
        return farmer;
    }

    public List<CartItem> getItems() {
        return items;
    }

    public BigDecimal getSubtotal() {
        return subtotal;
    }
} 